﻿using CPPEI.Coolzon.Common;
using CPPEI.Coolzon.Data;
using CPPEI.Coolzon.Server.CacheData;
using CPPEI.Coolzon.Service.Contract;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CPPEI.Coolzon.Server.ServiceImplement
{
    public class ReqCheckClientStatusHandler : BaseHandler<ReqCheckClientStatusData, RespCheckClientStatusData>
    {
        public ReqCheckClientStatusHandler()
            : base(RESPONSE_SCENARIO.CONNENT, RESPONSE_COMMAND.CONNECT.CHECKCLIENTSTATUS)
        {
        }

        protected override RespCheckClientStatusData OnHandle(Data.MainServiceData.Request request, ReqCheckClientStatusData requestData)
        {
            RespCheckClientStatusData responseData = new RespCheckClientStatusData();
            responseData.IsPass = true;
            CacheData.ControlDomain domain = ServerData.Instance.GetDomain(request.Header.DomainId);
            if (domain != null)
            {
                List<CacheData.Client> clients = domain.GetClientList();
                foreach (var client in clients)
                {
                    if(!CacheDataUtil.IsLiveTimeout(client) && client.Status != requestData.Status)
                    {
                        responseData.IsPass = false;
                        break;
                    }
                }
            }
            else
            {
                responseData.IsPass = false;
            }
            return responseData;
        }
    }
}
